/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import DragTable from '@/components/DragTable';
import ProTable from '@ant-design/pro-table';
import type { ActionType, ProColumns } from '@ant-design/pro-table';

import { getLeagueFeeApplyLog, setLeagueApplyCheck } from '@/services/Inn/ChargeCheck';
import { Input, Popconfirm, Space } from 'antd';

const ChargeCheck: React.FC = () => {
  const actionRef = useRef<ActionType>();

  const columns: ProColumns<Record<string, string>>[] = [
    {
      title: '',
      dataIndex: 'keywords',
      hideInTable: true,
      renderFormItem: () => <Input placeholder='请输入加盟商手机号、id或名称' />,
    },
    {
      title: '序号',
      dataIndex: 'order',
      align: 'center',
      search: false,
    },
    {
      title: 'id',
      dataIndex: 'league_id',
      align: 'center',
      search: false,
    },
    {
      title: '加盟商名称',
      dataIndex: 'league_name',
      align: 'center',
      search: false,
    },
    {
      title: '申请时间',
      dataIndex: 'create_at',
      align: 'center',
      search: false,
    },
    {
      title: '联系人',
      dataIndex: 'contact_name',
      align: 'center',
      search: false,
    },
    {
      title: '原入库服务费(元)',
      dataIndex: 'original_fee',
      align: 'center',
      search: false,
    },
    {
      title: '申请入库服务费(元)',
      dataIndex: 'apply_fee',
      align: 'center',
      search: false,
    },
    {
      title: '操作时间',
      dataIndex: 'operate_at',
      align: 'center',
      search: false,
    },
    {
      title: '操作',
      align: 'center',
      search: false,
      render: (_, record) => {
        const { op_status, check_status_desc, id } = record;
        if (op_status == '0') {
          return (
            <Space>
              <Popconfirm
                title='确定拒绝？'
                onConfirm={setLeagueApplyCheck.bind(null, {
                  id,
                  check_status: 2,
                  then: actionRef.current?.reload,
                })}
              >
                <a>拒绝</a>
              </Popconfirm>

              <Popconfirm
                title='确定通过？'
                onConfirm={setLeagueApplyCheck.bind(null, {
                  id,
                  check_status: 1,
                  then: actionRef.current?.reload,
                })}
              >
                <a>通过</a>
              </Popconfirm>
            </Space>
          );
        } else {
          return '已' + check_status_desc;
        }
      },
    },
  ];

  return (
    <PageContainer>
      <DragTable>
        <ProTable<Record<string, string>>
          actionRef={actionRef}
          rowKey='id'
          request={getLeagueFeeApplyLog}
          pagination={{
            pageSize: 20,
            showQuickJumper: false,
            showSizeChanger: false,
          }}
          columns={columns}
          options={false}
          scroll={{ x: 1200 }}
          search={{
            className: 'kb-pro-table-form',
            collapseRender: () => false,
          }}
        />
      </DragTable>
    </PageContainer>
  );
};

export default ChargeCheck;
